﻿using nblTool.utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebFirst.Entities;

namespace Jn698._45GWTool.Services
{
    public class GWCmdMakeUpService
    {
        public GWCmdMakeUp Select(int Id)
        {
            return SqlSugarHelper.Db.Queryable<GWCmdMakeUp>().Single(x => x.Id == Id);
        }

        public GWCmdMakeUp Select(string Name)
        {
            SqlSugarHelper.Db.Queryable<GWCmdMakeUp>().Where(g => g.ObjectIdentifier.Equals(Name)).ToList();
            return null;
        }
        public List<GWCmdMakeUp> Select(ObjectID objectID)
        {
            int AttributeID = (int)objectID.AttributeID;
            string OAD;
            if (objectID._ObjectID.Length == 4)
            {
                OAD = objectID._ObjectID.ToString() + AttributeID.ToString("X2") + "00";
            }
            else
            {
                OAD = objectID._ObjectID.ToString();

            }

            return SqlSugarHelper.Db.Queryable<GWCmdMakeUp>().Where(g => g.ObjectIdentifier.Equals(OAD)).Where(g => g.OpenrateType.Equals(objectID.ClientAPDU)).ToList();
        }
        public List<GWCmdMakeUp> SelectByOAD(string OAD)
        {
            return SqlSugarHelper.Db.Queryable<GWCmdMakeUp>().Where(g => g.ObjectIdentifier.Equals(OAD)).ToList();
        }
        public int Update(GWCmdMakeUp t)
        {
            return SqlSugarHelper.Db.Updateable(t).ExecuteCommand();
        }
        public int UpdateValue(GWCmdMakeUp t)
        {
            return SqlSugarHelper.Db.Updateable(t).UpdateColumns(g => new { g.DataValue }).ExecuteCommand();
        }
    }
}
